package com.mine.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mine.pojo.MinePublishContentCategory;
import com.mine.result.CodeMsg;
import com.mine.result.Result;
import com.mine.service.PublishService;
import com.mine.vo.PublishVo;

@Controller
public class PublishController {

	@Autowired
	PublishService publishService;
	//添加一条发布内容
	@RequestMapping(value="/publish/add/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result addPublishContent(@PathVariable String token, @RequestBody PublishVo publishVo){
		if (publishVo==null||token==null||publishVo.getCategoryId()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		Result result = publishService.addPublishContent(token,publishVo);
		return result;
	}
	//修改一条发布内容
	@RequestMapping(value="/publish/update/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result updatePublishContent(@PathVariable String token, @RequestBody PublishVo publishVo){
		if (publishVo==null||token==null||publishVo.getId()==null||publishVo.getCategoryId()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		Result result = publishService.updatePublishContent(token,publishVo);
		return result;
	}
	//删除一条发布内容
	@RequestMapping(value="/publish/delete/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result deletePublishContent(@PathVariable String token, @RequestBody PublishVo publishVo){
		if (publishVo==null||token==null||publishVo.getId()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		Result result = publishService.deletePublishContent(token,publishVo);
		return result;
	}
	
	//查询一条发布内容
	@RequestMapping(value="/publish/get/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result getPublishContent(@PathVariable String token, @RequestBody PublishVo publishVo){
		if (publishVo==null||token==null||publishVo.getId()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		Result result = publishService.getPublishContent(token,publishVo);
		return result;
	}
	
	//根据分类，获取发布列表
	@RequestMapping(value="/publish/getList/{token}/{categoryId}")
	@ResponseBody
	public Result getPublishContentList(@PathVariable String token, @PathVariable Long categoryId){
		if (categoryId==null||token==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		Result result = publishService.getPublishContentList(token,categoryId);
		return result;
	}
		
	//添加发布内容分类
	@RequestMapping(value="/publishCategory/add/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result addPublishCategory(@PathVariable String token, @RequestBody MinePublishContentCategory contentCategory){
		if (contentCategory==null||token==null||contentCategory.getCategoryName()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		
		Result result = publishService.addPublishCategory(token,contentCategory);
		return result;
	}
	
	//删除发布内容分类
	@RequestMapping(value="/publishCategory/delete/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result deletePublishCategory(@PathVariable String token, @RequestBody MinePublishContentCategory contentCategory){
		if (contentCategory==null||token==null||contentCategory.getId()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		
		Result result = publishService.deletePublishCategory(token,contentCategory);
		return result;
	}
	//修改发布内容分类
	@RequestMapping(value="/publishCategory/update/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result updatePublishCategory(@PathVariable String token, @RequestBody MinePublishContentCategory contentCategory){
		if (contentCategory==null||token==null||contentCategory.getId()==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		
		Result result = publishService.updatePublishCategory(token,contentCategory);
		return result;
	}
	//获取该用户发布内容分类
	@RequestMapping(value="/publishCategory/getList/{token}",method=RequestMethod.POST)
	@ResponseBody
	public Result getPublishCategory(@PathVariable String token){
		if (token==null) {
			return Result.error(CodeMsg.BIND_ERROR);
		}
		
		Result result = publishService.getPublishCategory(token);
		return result;
	}
	
}
